package org.boge.sharpdoc.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.boge.sharpdoc.dao.CommentDao;
import org.boge.sharpdoc.bean.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CommentService {
    @Autowired
    private CommentDao commentDao;

    public Integer commitComment(Comment comment) {
        return commentDao.addNewComment(comment);
    }

    public PageInfo<Comment> getAllWithPage(Integer index, Integer pageSize) {
        return PageHelper.startPage(index, pageSize, "publishtime desc").doSelectPageInfo(() -> commentDao.findAll());
    }
}